package utils;

import java.util.ArrayList;

import junit.framework.Assert;
import junit.framework.TestCase;
import utils.Sort.SortPvClick;

//import utils.Sort.SortPvClick;

public class SortTest extends TestCase {

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testQuickSortInt() {
		int[] pData = { 1, 84, 85, 67, 600, 88, 999 };
		Sort.quickSortInt(pData, 0, pData.length - 1);
		int[] testData = { 1, 67, 84, 85, 88, 600, 999 };
		for (int i = 0; i < pData.length; i++) {
			Assert.assertEquals(testData[i], pData[i]);
		}
	}

	 public void testQuickSortCredit() {
		 ArrayList<SortPvClick> toSort = new ArrayList<SortPvClick>();
		 toSort.add(new SortPvClick("a", 1, 2.0));
		 toSort.add(new SortPvClick("b", 5, 6.2));
		 toSort.add(new SortPvClick("c", 3, 100));
		 toSort.add(new SortPvClick("d", 2, 50.1));
		 toSort.add(new SortPvClick("e", 10, 1));
		 toSort = Sort.quickSortCredit(toSort, 0, toSort.size() - 1);
		 Assert.assertEquals(10, toSort.get(0).credit);
		 Assert.assertEquals(5, toSort.get(1).credit);
		 Assert.assertEquals(3, toSort.get(2).credit);
		 Assert.assertEquals(2, toSort.get(3).credit);
		 Assert.assertEquals(1, toSort.get(4).credit);
	 }
	 
	 public void testQuickSortPrice() {
		 ArrayList<SortPvClick> toSort = new ArrayList<SortPvClick>();
		 toSort.add(new SortPvClick("a", 1, 2.0));
		 toSort.add(new SortPvClick("b", 5, 6.2));
		 toSort.add(new SortPvClick("c", 3, 100));
		 toSort.add(new SortPvClick("d", 2, 50.1));
		 toSort.add(new SortPvClick("e", 10, 1));
		 toSort = Sort.quickSortPrice(toSort, 0, toSort.size() - 1);
		 Assert.assertEquals(100, toSort.get(0).price, 0.1);
		 Assert.assertEquals(50.1, toSort.get(1).price, 0.1);
		 Assert.assertEquals(6.2, toSort.get(2).price, 0.1);
		 Assert.assertEquals(2.0, toSort.get(3).price, 0.1);
		 Assert.assertEquals(1, toSort.get(4).price, 0.1);
	 }
	 
	 public void testDate() {
		 long t1 = Utils.getTimeSpan("20100617235958", "20100618000001");
		 System.out.println(t1);
	 }
	 /*
	 public void testQuickSortDate() throws ParseException {
		 SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
		 ArrayList<SortDate> toSort = new ArrayList<SortDate>();
		 toSort.add(new SortDate("a", df.parse("20100101111111")));
		 toSort.add(new SortDate("b", df.parse("20100107010101")));
		 toSort.add(new SortDate("c", df.parse("20100105232323")));
		 toSort.add(new SortDate("d", df.parse("20100102131313")));
		 toSort.add(new SortDate("e", df.parse("20100103212121")));
		 toSort = Sort.quickSortDate(toSort, 0, toSort.size() - 1);
		 System.out.println(toSort);
		 Assert.assertEquals(10, toSort.get(0).date);
		 Assert.assertEquals(5, toSort.get(1).date);
		 Assert.assertEquals(3, toSort.get(2).date);
		 Assert.assertEquals(2, toSort.get(3).date);
		 Assert.assertEquals(1, toSort.get(4).date);
	 }
*/
}
